package psu.kit;

public class ArrayHandler {

    public int handelArray(int[] array) {
        int count = countNonZero(array);
        if (count != array.length && count != 0) {
            int k = array.length - 1;
            for (int i = 0; i < k; ++i) {
                if (array[i] == 0) {
                    while (array[k] == 0) {
                        k--;
                    }
                    array[i] = array[k];
                    array[k] = 0;
                    k--;
                }
            }
        }
        return count;
    }

    private int countNonZero(int array[]) {
        int count = 0;
        for (int elementOfArray : array) {
            if (elementOfArray != 0) {
                count++;
            }
        }
        return count;
    }

}
